package com.xlt.activiti.one;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;

import java.util.List;
// 查询流程定义
public class ActivitiProcessQuery {
    public static void queryProcessDefinition(String key){
        // 1.得到processEngine对象
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        // 2.获取repositoryService
        RepositoryService repositoryService = processEngine.getRepositoryService();
        // 3.查询流程定义
        ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
        // 4.遍历查询结果
        List<ProcessDefinition> list = processDefinitionQuery.
                processDefinitionKey(key).orderByProcessDefinitionVersion().desc().list();
        for (ProcessDefinition processDefinition:list){

            System.out.println("---------------------");
            System.out.println("流程部署ID"+processDefinition.getDeploymentId());
            System.out.println("流程定义ID"+processDefinition.getId());
            System.out.println("流程定义名称"+processDefinition.getName());
            System.out.println("流程定义KEY"+processDefinition.getKey());
            System.out.println("流程定义版本"+processDefinition.getVersion());
        }
    }
}
